import React from 'react'
import { Layout} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import {useSelector,useDispatch,connect} from 'react-redux'
import "./tr.css"

const {Content} = Layout;



const User = () => {

    const userList = useSelector(state=> state.user.userList)
    const valueList = useSelector(state=> state.value.valueList)
    const dispatch = useDispatch()
  let value;
  
  const columns = [
    {
      title: '用户头像',
      key: 'user_img',
      dataIndex: 'user_img',
      valueType: 'avatar',
      hideInSearch:true
    },
    {
        title: '用户名',
        dataIndex: 'user_name',
        key: 'user_name',
        ellipsis:true
    },
    {
        title: '用户账号',
        key: 'user_number',
        dataIndex: 'user_number',
        valueType: 'text',
    },
    {
      title: '用户密码',
      key: 'user_pwd',
      dataIndex: 'user_pwd',
      valueType: 'text',
    },
    {
      title: '用户性别',
      key: 'user_sex',
      dataIndex: 'user_sex',
      valueType: 'text',
    },
    {
      title: '用户考研年份',
      key: 'user_year',
      dataIndex: 'user_year',
      valueType: 'text',
    },
    {
      title: '用户专业',
      key: 'user_major',
      dataIndex: 'user_major',
      valueType: 'text',
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});
        }}><Editor ques={user} url="http://101.34.58.111:8081"/></div>
        , <a onClick={async ()=>{
          await fetch(`http://101.34.58.111:8081/${record.user_number}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          },
          body:JSON.stringify(record)
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];
const right = {
}

  const user = [
    {name:'user_name',label:'用户名',tooltip:'最长为24位',placeholder:'请输入用户名称'},
    {name:'user_img',label:'用户头像',placeholder:'上传头像'},
    {name:'user_number',label:'用户账号',tooltip:'最长为24位',placeholder:'请输入账号'},
    {name:'user_pwd',label:'用户密码',tooltip:'最长为24位',placeholder:'请输入密码'},
    {name:'user_sex',label:'用户性别',tooltip:'最长为24位',placeholder:'请输入性别'},
    {name:'user_year',label:'用户考研年份',tooltip:'最长为24位',placeholder:'请输入考研年份'},
    {name:'user_major',label:'用户专业',tooltip:'最长为24位',placeholder:'请输入专业'}
]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280,}}>
          <Table title="用户管理" columns={columns} right={right} url="http://101.34.58.111:8081" ques={user} />
        </Content>
    )
}

export default connect()(User)